package com.huawei.appmarket.service.infoflow.view.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.FrameLayout;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.infoflow.view.widget.PullDownListView;
import com.huawei.appmarket.service.infoflow.view.widget.TopTipsView;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import o.azb;
import o.cfv;
import o.chd;
import o.cia;
import o.cih;
import o.cjk;
import o.cjm;
import o.cjo;
import o.BaseRequest;
import o.AsyLoader;
import o.dgh;
import o.dky.g;
import o.dky.h;
import o.dky.i;
import o.dky.j;
import o.Logger;
import o.doo;
import o.ContentManager;
import o.eae;
import o.eah;
import o.eak;
import o.epr;
import o.evk;
import o.ll;

public class InfoFlowFragment extends AppListFragment {
    private Handler ʹ = new Handler();
    protected String ˊ;
    private b ॱॱ;
    private TopTipsView ᐝ;
    private PullDownListView ﹳ;
    private int ﾞ = 0;
    private FrameLayout ﾟ;

    static class a implements com.huawei.appmarket.service.infoflow.view.widget.PullDownListView.b {
        private WeakReference<InfoFlowFragment> ˋ;

        private a(InfoFlowFragment infoFlowFragment) {
            this.ˋ = null;
            this.ˋ = new WeakReference(infoFlowFragment);
        }

        public void ˊ() {
            if (this.ˋ != null) {
                InfoFlowFragment infoFlowFragment = (InfoFlowFragment) this.ˋ.get();
                if (infoFlowFragment != null) {
                    infoFlowFragment.ʾˋ();
                }
            }
        }
    }

    static class b extends SafeBroadcastReceiver {
        private WeakReference<InfoFlowFragment> ˊ = null;

        public b(InfoFlowFragment infoFlowFragment) {
            this.ˊ = new WeakReference(infoFlowFragment);
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                InfoFlowFragment infoFlowFragment = (InfoFlowFragment) this.ˊ.get();
                String action = intent.getAction();
                if (action != null && !action.isEmpty() && infoFlowFragment != null) {
                    if (o.dvf.b.ॱ.equals(action)) {
                        infoFlowFragment.ـॱ.notifyDataSetChanged();
                    } else if ("cardlist_show_toast_action".equals(action)) {
                        Object stringExtra = intent.getStringExtra("toast_tips");
                        if (!TextUtils.isEmpty(stringExtra) && infoFlowFragment.ᵔ && infoFlowFragment.ᐨॱ) {
                            evk.ˏ();
                            evk.ॱ(stringExtra, 0).ˋ();
                            return;
                        }
                        Logger.ˎ("InfoFlowFragment", "onReceive, tips: " + stringExtra + ", isSelected = " + infoFlowFragment.ᵔ + ", isOnResumed = " + infoFlowFragment.ᐨॱ);
                    }
                }
            }
        }
    }

    static class c implements AnimationListener {
        private WeakReference<PullDownListView> ॱ;

        public c(PullDownListView pullDownListView) {
            this.ॱ = new WeakReference(pullDownListView);
        }

        public void onAnimationStart(Animation animation) {
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationEnd(Animation animation) {
            if (this.ॱ != null) {
                PullDownListView pullDownListView = (PullDownListView) this.ॱ.get();
                if (pullDownListView != null) {
                    pullDownListView.setmPullRefreshing(false);
                }
            }
        }
    }

    static class d implements o.eak.e {
        private WeakReference<InfoFlowFragment> ˊ;

        public d(InfoFlowFragment infoFlowFragment) {
            this.ˊ = new WeakReference(infoFlowFragment);
        }

        public void ॱ(int i) {
            if (this.ˊ != null) {
                InfoFlowFragment infoFlowFragment = (InfoFlowFragment) this.ˊ.get();
                if (infoFlowFragment != null) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("InfoFlowFragment", "onReceivedDataSize, showTopTips");
                    }
                    infoFlowFragment.ˏ(infoFlowFragment.ᐝॱ().getQuantityString(g.ˊ, i, new Object[]{Integer.valueOf(i)}), o.dky.d.ʽॱ);
                    return;
                }
                Logger.e("InfoFlowFragment", "AnalyseResListenerImpl, onReceivedDataSize, flowFragment == null");
                return;
            }
            Logger.e("InfoFlowFragment", "AnalyseResListenerImpl, onReceivedDataSize, fragmentRef == null");
        }

        public void ˋ() {
            if (this.ˊ != null) {
                InfoFlowFragment infoFlowFragment = (InfoFlowFragment) this.ˊ.get();
                if (infoFlowFragment != null) {
                    if (Logger.ˎ()) {
                        Logger.ˏ("InfoFlowFragment", "onReceivedNoData, showTopTips");
                    }
                    infoFlowFragment.ˏ(infoFlowFragment.ॱ(j.ˊˊ), o.dky.d.ʾ);
                    AsyLoader.ˋ(infoFlowFragment.ʻᐝ);
                    return;
                }
                Logger.e("InfoFlowFragment", "AnalyseResListenerImpl, onReceivedDataSize, flowFragment == null");
                return;
            }
            Logger.e("InfoFlowFragment", "AnalyseResListenerImpl, onReceivedNoData, fragmentRef == null");
        }
    }

    static class e implements Runnable {
        private WeakReference<InfoFlowFragment> ॱ;

        private e(InfoFlowFragment infoFlowFragment) {
            this.ॱ = null;
            this.ॱ = new WeakReference(infoFlowFragment);
        }

        public void run() {
            if (this.ॱ != null) {
                InfoFlowFragment infoFlowFragment = (InfoFlowFragment) this.ॱ.get();
                if (infoFlowFragment != null) {
                    infoFlowFragment.י();
                }
            }
        }
    }

    public void ˏ(Bundle bundle) {
        this.ॱꜟ = true;
        super.ˏ(bundle);
        this.ˊ = ˊʻ();
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        if (this.ͺˎ instanceof PullDownListView) {
            this.ﹳ = (PullDownListView) this.ͺˎ;
            this.ﹳ.setHeaderLayoutListener(new a());
            this.ﹳ.setInterceptScrollOnBottom(true);
            this.ﹳ.setNeedFootView(false);
            this.ﹳ.setmPullRefreshing(false);
        }
        ˋ(this.ॱˍ);
        this.ᐝ = (TopTipsView) this.ॱˍ.findViewById(h.ᐧ);
        return this.ॱˍ;
    }

    public void ˌ() {
        super.ˌ();
        if (this.ᵔ) {
            this.ʾॱ = dgh.ॱ();
            if (Logger.ˎ()) {
                Logger.ˏ("InfoFlowFragment", "onResume analyticToken");
            }
        }
    }

    public void ˋᐝ() {
        super.ˋᐝ();
        if (this.ᵔ) {
            dgh.ˋ("340501", ٴ());
            if (Logger.ˎ()) {
                Logger.ˏ("InfoFlowFragment", "onPause analyticToken");
            }
        }
    }

    public void ᐝ() {
        super.ᐝ();
        ʽʽ();
        if (this.ͺˎ != null) {
            this.ͺˎ.setmPullRefreshing(false);
        }
    }

    public void ʾˊ() {
    }

    public void ˋ(int i) {
        super.ˋ(i);
        if (this.ᐨॱ) {
            this.ʾॱ = dgh.ॱ();
            if (Logger.ˎ()) {
                Logger.ˏ("InfoFlowFragment", "onColumnSelected analyticToken");
            }
        }
    }

    public void ʽˊ() {
        super.ʽˊ();
        if (this.ᐨॱ) {
            dgh.ˋ("340501", ٴ());
            if (Logger.ˎ()) {
                Logger.ˏ("InfoFlowFragment", "onColumnUnselected analyticToken");
            }
        }
    }

    private LinkedHashMap<String, String> ٴ() {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("detailID", this.ʼˊ);
        linkedHashMap.put("time", String.valueOf(System.currentTimeMillis() - this.ʾॱ));
        return linkedHashMap;
    }

    protected void ˋ(ViewGroup viewGroup) {
        Context ॱˊ = ॱˊ();
        if (viewGroup == null || ॱˊ == null) {
            Logger.ˋ("InfoFlowFragment", "initContentLayout, rootView = " + viewGroup);
            return;
        }
        eah.ˋ().ˎ(ॱˊ);
        this.ﾟ = (FrameLayout) viewGroup.findViewById(h.ˏˏ);
        if (!epr.ˎ().ॱॱ() && azb.ˎ(ॱˊ)) {
            int ॱ = eah.ˋ().ॱ(ॱˊ);
            LayoutParams layoutParams = this.ﾟ.getLayoutParams();
            layoutParams.width = ॱ;
            this.ﾟ.setLayoutParams(layoutParams);
        }
    }

    protected String ˊʻ() {
        return this.ʼˊ + System.currentTimeMillis();
    }

    public void ᵔ() {
        ˎ(this.ॱˍ);
    }

    public cia ˊ(Context context) {
        return new eae(context);
    }

    public void ॱﾟ() {
        this.ॱꜞ = new eak(new d(this));
    }

    public int ߵ() {
        return i.ʻ;
    }

    public boolean ﹳॱ() {
        return false;
    }

    public boolean ad_() {
        return false;
    }

    public com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b ʽʻ() {
        return null;
    }

    public void ˊ(cfv o_cfv) {
        BaseRequest.RequestStrategy cVar = BaseRequest.RequestStrategy.ˏ;
        if (this.ॱꜟ && this.ˏ == 1) {
            this.ॱꜟ = false;
            cVar = BaseRequest.RequestStrategy.ˋ;
            Logger.ˎ("InfoFlowFragment", "setRequestType REQUEST_CACHE_FIRST");
        }
        o_cfv.setRequestType(cVar);
        o_cfv.ˏ(this.ʼˊ);
    }

    public void ॱ(chd o_chd) {
    }

    public boolean ˏ(chd o_chd, DetailResponse detailResponse) {
        if (this.ˏ == 1 && this.ͺˎ != null) {
            this.ͺˎ.setmPullRefreshing(false);
        }
        if (detailResponse.getResponseType() == com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a.ॱ) {
            this.ˏ = o_chd.ˏ() + 1;
            Logger.ˎ("InfoFlowFragment", "onAfterUpdateProvider nextPageNum = " + this.ˏ);
        } else if (detailResponse.getResponseType() == com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a.ˏ) {
            if (Logger.ˎ()) {
                Logger.ˏ("InfoFlowFragment", "ResponseBean.ResponseDataType.FROM_CACHE");
            }
            this.ʹ.postDelayed(new e(), 50);
        }
        return true;
    }

    public void ˋ(com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
    }

    public void ˊ(ResponseBean responseBean) {
        super.ˊ(responseBean);
        if (responseBean.getRtnCode_() == 10) {
            this.ˏ++;
        }
    }

    public void ˎ(ResponseBean responseBean) {
        if (Logger.ˎ()) {
            Logger.ˏ("InfoFlowFragment", "onHandlePullRefreshError, showTopTips, rtnCode = " + responseBean.getRtnCode_());
        }
        int ˏ = ˏ(responseBean);
        if (this.ՙ == null || 3 != ˏ) {
            ˏ(ॱ(j.ˊˊ), o.dky.d.ʾ);
            return;
        }
        if (this.ﹳ != null) {
            this.ﹳ.ʼॱ();
            this.ﹳ.setmPullRefreshing(false);
        }
        this.ՙ.ॱ();
    }

    public void ˈॱ() {
        ॱʾ();
        ʿˊ();
    }

    public void ˌॱ() {
        super.ˌॱ();
        this.ॱॱ = new b(this);
        IntentFilter intentFilter = new IntentFilter(o.dvf.b.ॱ);
        intentFilter.addAction("cardlist_show_toast_action");
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.ॱॱ, intentFilter);
    }

    public void ˋʼ() {
        super.ˋʼ();
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ॱॱ);
        this.ॱॱ = null;
    }

    public void ꜞॱ() {
        if (this.ﹳ == null || this.ﹳ.getVisibility() != 0) {
            Logger.e("InfoFlowFragment", "goBackToTop, pullDownListView = " + this.ﹳ);
            return;
        }
        if (!ʻʼ()) {
            this.ﹳ.ʽ();
        }
        if (doo.ˊ(ॱˋ()) || this.י.ˊॱ() > 0) {
            this.ﹳ.ʽॱ();
        }
    }

    private void י() {
        ꜞॱ();
    }

    private void ॱʾ() {
        dgh.ˋ("340502", ߺ());
        if (Logger.ˎ()) {
            Logger.ˏ("InfoFlowFragment", "reportRefreshTimes, pullRefreshSize = " + this.ﾞ);
        }
    }

    private LinkedHashMap<String, String> ߺ() {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("detailID", this.ʼˊ);
        int i = this.ﾞ + 1;
        this.ﾞ = i;
        linkedHashMap.put("times", String.valueOf(i));
        return linkedHashMap;
    }

    private void ˏ(String str, int i) {
        if (this.ﹳ != null) {
            this.ﹳ.ʼॱ();
        }
        if (this.ᐝ != null) {
            this.ᐝ.setTips(str);
            this.ᐝ.ॱ(new c(this.ﹳ));
            this.ᐝ.setBackgroundResource(i);
        }
    }

    public void ˏ(int i, cih o_cih) {
        if (i == 11) {
            י();
        } else {
            super.ˏ(i, o_cih);
        }
    }

    public void ˏ(BaseCardBean baseCardBean) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request(baseCardBean.ॱॱ(), baseCardBean.u_());
        request.ˏॱ(baseCardBean.ˌॱ());
        appDetailActivityProtocol.ˏ(request);
        cjk.ˎ().ˋ(ॱˊ(), new cjm("appdetail.activity", appDetailActivityProtocol));
    }
}
